package xyz.labradormm.auth.domain.dto;

import lombok.Data;
import lombok.experimental.Accessors;
import xyz.labradormm.auth.enums.StatusCode;

import java.io.Serializable;

/**
 * @author hhj
 * @description
 * @date 2023-03-29 9:52
 * @menu
 */
@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private int code;

    private String msg;

    private T data;

    public Result() {
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    public static Result success() {
        return new Result(StatusCode.SUCCESS);
    }

    public static Result fail() {
        return new Result(StatusCode.FAIL);
    }

    public static Result fail(StatusCode statusCode) {
        return new Result(statusCode);
    }


}
